var http = require("http");
var url = require("url");
var port = 8888;

function start(route, handler){
    http.createServer(onRequest).listen(port);
    console.log("Server running: http://127.0.0.1:" + port);

    function onRequest(req, res){
        setImmediate(function(){
            var pathname = url.parse(req.url).pathname;
            console.log("Request for '" + pathname + "' recieved.");

            route(handler, pathname, res);
        });
    }
}

exports.start = start;